import { ColorRepresentation, MaterialParameters, SpriteMaterial } from "../../thirdparty/three/imports";
import { Texture3D } from "../textures/Texture3D";
import { Material3D } from "./Material3D";

export interface SpriteMaterial3D
{
    get _material(): SpriteMaterial;
    set _material(v: SpriteMaterial);
}

export interface SpriteMaterialParameters extends MaterialParameters
{
    color?: ColorRepresentation | undefined;
    map?: Texture3D | null | undefined;
    alphaMap?: Texture3D | null | undefined;
    rotation?: number | undefined;
    sizeAttenuation?: boolean | undefined;
    fog?: boolean | undefined;
}

export class SpriteMaterial3D extends Material3D
{
    get color()
    {
        return this._material.color;
    }
    set color(v)
    {
        this._material.color = v;
    }

    get map()
    {
        if (this._material)
        {
            this._map = Texture3D.get(this._material.map);
        }

        return this._map;
    }
    set map(v)
    {
        this._map = v;
        if (this._material)
        {
            this._material.map = v._texture;
        }
    }
    private _map: Texture3D;

    constructor(parameters?: SpriteMaterialParameters)
    {
        super();

        if (parameters?.map)
        {
            parameters.map = parameters.map._texture as any;
        }
        if (parameters?.alphaMap)
        {
            parameters.alphaMap = parameters.alphaMap._texture as any;
        }

        this._material = new SpriteMaterial(parameters as any);
    }
}
